package org.brownflat.watergate.resources.mysql;

import org.brownflat.watergate.resources.MySqlUpgrade;
import org.springframework.stereotype.Component;

/**
 * <p>&copy Rupert Jones 2011,2012</p>
 *
 * @author rup
 */
@Component
public class Upgrade0003ProjectStructure implements MySqlUpgrade {

    private static final int VERSION = 3;

    @Override
    public int getSequence() {
        return VERSION;
    }

    @Override
    public String getSql() {
          return "CREATE TABLE `wgate_project` (\n"
                + "  `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + "  `name` varchar(100) NOT NULL,\n"
                  + "  `created_at` timestamp NOT NULL,\n"
                  + "  `updated_at` timestamp NOT NULL,\n"
                + "  PRIMARY KEY (`id`),\n"
                + "  UNIQUE KEY `name_UNIQUE` (`name`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\n"
                + "\n"
                + "CREATE TABLE `wgate_project_role`(\n"
                + " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + "  `name` varchar(100) NOT NULL,\n"
                  + "  `created_at` timestamp NOT NULL,\n"
                  + "  `updated_at` timestamp NOT NULL,\n"
                + "  PRIMARY KEY (`id`),\n"
                + "  UNIQUE KEY `name_UNIQUE` (`name`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\n"
                + "\n"
                + "CREATE TABLE `wgate_project_user_role`(\n"
                + " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + " `project_id` int(11) NOT NULL,\n"
                + " `role_id` int(11) NOT NULL,\n"
                + " `user_id` int(11) NOT NULL,\n"
                + "  PRIMARY KEY (`id`),\n"
                + "  UNIQUE KEY `role_project_UNIQUE` (`project_id`, `role_id`, `user_id`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\n";
    }

    @Override
    public String getName() {
        return "Create project structure";
    }
}
